package com.banyuan.课堂练习.Thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/*
 * 1、创建一个线程类：run方法生成10个随机数，返回最大的整数[1-100]；
 * 2、启动两个线程同时进行；
 * 3，计算两个最大的整数差；
 * */
public class Ex1 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable<Integer> d1 = new Demo1();
        Callable<Integer> d2 = new Demo1();
        FutureTask<Integer> futureTask1 = new FutureTask<>(d1);
        FutureTask<Integer> futureTask2 = new FutureTask<>(d2);
        Thread th1 = new Thread(futureTask1);
        Thread th2 = new Thread(futureTask2);
        th1.start();
        th2.start();
        int n1 = futureTask1.get();
        System.out.println(n1);
        int n2 = futureTask2.get();
        System.out.println(n2);
        System.out.println(Math.abs(n1 - n2));
    }
}
